/**
 *@Time    : 2021/11/11 20:51
 *@Author  : Shuai Jhou
 *@File    : server
 *@Software: GoLand
 */

package main

import (
	"go.zhoushuai.cn/go-programming-tour-book/grpc-pratice/middleware"
	"go.zhoushuai.cn/go-programming-tour-book/grpc-pratice/services"
	"net"
)

func main() {

	//grpcServer := grpc.NewServer(grpc.Creds(helper.GetServerCreds()))
	// 实现多个拦截器
	//opts := []grpc.ServerOption{
	//	grpc.ChainUnaryInterceptor(HelloInterceptor, WordInterceptor),
	//}
	//grpcServer := grpc.NewServer(opts...)
	grpcServer := middleware.RunGrpcServer()
	// 商品服务
	services.RegisterProdServiceServer(grpcServer, services.NewProdService())
	// 订单服务
	services.RegisterOrderServiceServer(grpcServer, new(services.OrderService))
	// 用户服务
	services.RegisterUserServiceServer(grpcServer, new(services.UserService))
	// ....等服务
	lis, _ := net.Listen("tcp", ":8081")
	grpcServer.Serve(lis)

	//serverMux := http.NewServeMux()
	//serverMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	//	log.Println(r.Proto)
	//	log.Println(r.Header)
	//	grpcServer.ServeHTTP(w, r)
	//	//_, _ = w.Write([]byte("pong"))
	//})
	//httpServer := &http.Server{Addr: ":8081", Handler: serverMux}
	//httpServer.ListenAndServeTLS("../keys/server.crt", "../keys/server.key")
}
